var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop: 0,
    introNavObj: {
      active: "0",
      fixed: !1
    },
    showOrgList: !1,
    selectCityIndex: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var tid = options.tid
    that.setData({
      tid: tid
    })
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.getTijiandetail()
    that.calculate()
  },
  calculate: function() {
    var t = this;
    wx.createSelectorQuery().select("#intro0").boundingClientRect().select("#intro1").boundingClientRect().select("#intro2").boundingClientRect().select("#intro-nav").boundingClientRect().exec(function(o) {
      var i = o[3].height;
      t.setData({
        "introNavObj.intro0": o[0].top - i,
        "introNavObj.intro1": o[1].top - i,
        "introNavObj.intro2": o[2].top - i,
        "introNavObj.introNav": o[3].top
      });
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  getTijiandetail() {
    var that = this
    var tid = that.data.tid
    app.util.request({
      'url': 'entry/wxapp/Tijian.detail',
      data: {
        tid: tid
      },
      success: function(res) {
        console.log(res)
        that.setData({
          detail: res.data
        })
      }
    })
  },
  showTip: function(e) {
    var t = e.currentTarget.dataset,
      o = t.clinicmeaning,
      n = t.itemName;
    o && wx.showModal({
      title: n,
      content: o,
      showCancel: !1,
      confirmColor: "#FD9238",
      confirmText: "我知道了"
    });
  },
  goScrollPosition: function(t) {
    var o = t.currentTarget.dataset.index;
    console.log(o)
    this.setData({
      "introNavObj.active": o,
    })
    wx.pageScrollTo({
      scrollTop: this.data.introNavObj["intro" + o] + 1
    });
  },
  onPageScroll: function(t) {
    this.goScroll(t);
  },
  goScroll: function(t) {
    var o = t.scrollTop,
      i = this.data.introNavObj,
      n = (i.intro0, i.intro1),
      e = i.intro2,
      r = i.introNav,
      a = "0";
    o >= e ? a = "2" : o >= n && o < e ? a = "1" : o < n && (a = "0"), this.data.showOrgList || this.setData({
      // "introNavObj.active": a,
      "introNavObj.fixed": o >= r,
      scrollTop: o
    });
  },
  showOrgList(s) {
    var that = this
    that.setData({
      showOrgList: !0
    })
    var tid = that.data.tid
    app.util.request({
      'url': 'entry/wxapp/Tijian.city',
      data: {
        tid: tid
      },
      'cachetime': '30',
      success: function(res) {
        // console.log(res)
        that.setData({
          cityOrgList: res.data.city
        })
        var ct_id = res.data.city[0].ct_id
        //查询下面的部门
        app.util.request({
          'url': 'entry/wxapp/Tijian.bumen',
          data: {
            ct_id: ct_id,
            tid: tid
          },
          'cachetime': '30',
          success: function(res) {
            // console.log(res)
            that.setData({
              bm: res.data
            })
          }
        })
      }
    })
  },
  selectCity(e) {
    console.log(e)
    var that = this
    var tid = that.data.tid
    var ct_id = e.currentTarget.dataset.ct_id
    var index = e.currentTarget.dataset.index
    // console.log(index)
    app.util.request({
      'url': 'entry/wxapp/Tijian.bumen',
      data: {
        ct_id: ct_id,
        tid: tid,
      },
      'cachetime': '30',
      success: function(res) {
        // console.log(res)
        that.setData({
          bm: res.data,
          selectCityIndex: index

        })
      }
    })
  },
  close: function() {
    this.setData({
      showOrgList: false
    })
  },
  closeList: function() {
    this.setData({
      showOrgList: !1
    })
  },
  goNext(e) {
    console.log(e)
    var that = this
    var tid = that.data.tid
    var title = e.currentTarget.dataset.title
    var count = e.currentTarget.dataset.count
    var money = e.currentTarget.dataset.money
    var project = e.currentTarget.dataset.project
    var detail = JSON.stringify(that.data.detail) 
    console.log(that.data.detail)
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/tijian/physical/appoint/appoint?tid=' + tid + '&count=' + count + '&money=' + money + '&detail=' + encodeURIComponent(JSON.stringify(that.data.detail)) + '&title=' + title + '&project=' + JSON.stringify(project),
    })
  }
})